using System;
using System.Collections.Generic;
namespace MicroMsg.UI.UserContrl
{
	public class LongTxtCutter
	{
		private const int MaxLineNum = 30;
		private const int CountPerLine = 23;
		private string originText;
		public List<string> textList = new List<string>();
		public LongTxtCutter(string text)
		{
			this.originText = text;
		}
		public void ProcessText()
		{
			string[] array = this.originText.Split(new string[]
			{
				"\n",
				"\r"
			}, 0);
			if (array == null)
			{
				this.textList.Add(this.originText);
				return;
			}
			List<string> list = new List<string>();
			for (int i = 0; i < array.Length; i++)
			{
				list.Add(array[i]);
			}
			this.CutLongString(list);
			LongTxtInfo longTxtInfo = new LongTxtInfo();
			for (int j = 0; j < list.get_Count(); j++)
			{
				int num = 0;
				for (int k = 0; k < list.get_Item(j).get_Length(); k++)
				{
					if (list.get_Item(j).get_Chars(k) <= '~' && list.get_Item(j).get_Chars(k) >= ' ')
					{
						num++;
					}
					else
					{
						num += 2;
					}
				}
				int num2 = (int)((double)num / 23.0 + 0.99);
				if (j == 0)
				{
					longTxtInfo.realTxt = list.get_Item(j);
					longTxtInfo.textLines = num2;
					longTxtInfo.wrapCount = 0;
				}
				else
				{
					if (longTxtInfo.textLines + num2 < 30)
					{
						LongTxtInfo expr_113 = longTxtInfo;
						expr_113.realTxt = expr_113.realTxt + "\n" + list.get_Item(j);
						longTxtInfo.wrapCount++;
						longTxtInfo.textLines += num2;
					}
					else
					{
						this.textList.Add(longTxtInfo.realTxt);
						longTxtInfo.Clear();
						longTxtInfo.realTxt = list.get_Item(j);
						longTxtInfo.wrapCount = 1;
						longTxtInfo.textLines = num2;
					}
				}
			}
			if (longTxtInfo.realTxt != "")
			{
				this.textList.Add(longTxtInfo.realTxt);
			}
		}
		private void CutLongString(List<string> strArray)
		{
			int i = 0;
			IL_AD:
			while (i < strArray.get_Count())
			{
				int num = 0;
				for (int j = 0; j < strArray.get_Item(i).get_Length(); j++)
				{
					if (strArray.get_Item(i).get_Chars(j) <= '~' && strArray.get_Item(i).get_Chars(j) >= ' ')
					{
						num++;
					}
					else
					{
						num += 2;
					}
					if (num / 23 >= 30)
					{
						string text = strArray.get_Item(i).Substring(0, j);
						string text2 = strArray.get_Item(i).Substring(j, strArray.get_Item(i).get_Length() - j);
						strArray.set_Item(i, text);
						if (i + 1 >= strArray.get_Count())
						{
							strArray.Add(text2);
						}
						else
						{
							strArray.Insert(i + 1, text2);
						}
						IL_A9:
						i++;
						goto IL_AD;
					}
				}
				goto IL_A9;
			}
		}
	}
}
